<template>
    <div class="contract-list-page contract-inquiry-list">
        <rui-page :defines="defines">

            <rui-query ref="formDom" :label-width="120" :query="queryData" :query-rows="formOptions"></rui-query>

            <rui-table
                ref="tableDom"
                defineId="defineData"
                ref-query="formDom"
                @loadDatas="queryData"
                :columns="tableColumns"
                :select="false"
                :showIndex="false"
                @on-row-dblclick="showContractDetial"
                :slots="[{key:'contractNo',slot:'contractNo'}]"
            >
                <template slot="contractNo" slot-scope="{ row }">
                    <a @click="showContractDetial(row)">{{row.contractNo}}</a>
                </template>
            </rui-table>
        </rui-page>
    </div>
</template>

<script>
    import {mapGetters} from "vuex";

    import defineData from "../defineData";
    import {channelType} from "_p/basic/api/contract/channel-type/channel-type";

    import {list} from "_p/basic/api/contract/contract-detail-inquiry";

    export default {
        // 合同明细列表
        name: "ContractInquiryList",
        data() {
            return {
                pageNo: 1, // 详情页页面id
                defines: [],
                isSP: false,
                spinShow: false,
                formOptions: [
                    {
                        defineId: "defineData",
                        span: 8,
                        fields: [
                            "contractNo",
                            "applyNo",
                            "phone",
                            "custName",
                            "certNo",
                            "channelName"
                        ]
                    }
                ],
                tableColumns: [
                    "contractNo",
                    "applyNo",
                    "custName",
                    "custRole",
                    "certNo",
                    "phone",
                    "contractStatus",
                    "channelType",
                    "startDate",
                    "endDate"
                ]
            };
        },
        computed: {
            ...mapGetters({userInfo: "userInfo", roleType: "roles"})
        },
        created() {
            this.defines.push({id: "defineData", fields: defineData});
            this.isSP = channelType(this.$route.meta.params);
        },
        mounted() {
            this.init();
            console.log("userInfo", this.userInfo, this.roleType);
            console.group("初始数据：");
            console.log("userInfo:", this.userInfo);
            console.log("pageParams:", this.pageParams);
            console.log("roleType:", this.roleType);
            console.log("isSP:", this.isSP);
            console.log("isApprove:", this.isApprove);
            console.log("contractNo:", this.contractNo);
            console.groupEnd();
        },

        methods: {
            init() {
                this.queryData(this.$refs.formDom.getFormData());
            },

            queryData(queryData) {
                if (this.loading || !queryData) return;
                this.loading = true;

                let data = Object.assign({}, queryData.condition, {
                    pageNumber: queryData.pageNumber,
                    pageSize: queryData.pageSize
                });
                console.log("queryData", data);

                list(data)
                    .then(res => {
                        if (res.code === "0000") {
                            let {records, total} = res.data;
                            this.$refs.tableDom.updateTableData(records, total);
                        }
                        this.loading = false;
                    })
                    .catch(e => {
                        console.error(e);
                        this.loading = false;
                    });
            },

            showContractDetial(params) {
                console.log("dbclcik params", params);
                if (!params && !params.contractNo) return;
                this.afs.newTab(
                    this,
                    "projects/basic/pages/contract/contract-inquiry/contract-inquiry-detial/index",
                    "合同明细详情",
                    "ios-add",
                    params,
                    "change-contact-detial-" + this.pageNo,
                    [],
                    true
                );
                this.pageNo += 1;
            }
        }
    };
</script>
<style lang="less">
    @import "../../../../styles/common/form.less";
</style>
